import { isEmpty } from '../utility/utility'

export function convertLevelData(level) {
  if (level) {
    const resultData = {
      label: level.indexName,
      value: level.indexName,
      pidName: level.pidName,
    }
    let children = []
    if (level.childList && level.childList.length) {
      children = level.childList.map(cItem => {
        return convertLevelData(cItem)
      })
    }
    if (children.length) {
      resultData.children = children
    }
    return resultData
  }
}

export function pushCycleFilter(val) {
  if (isEmpty(val)) {
    return '一年1次'
  }
  if (val === '0') {
    return '一年多次'
  } else if (val === '1-12') {
    return '一年1次'
  } else if (val === '1-6,7-12') {
    return '半年1次'
  } else if (val.includes(',')) {
    return val
      .split(',')
      .map(item => item + '月1次')
      .join('，')
  } else {
    return val + '月1次'
  }
}
